//
//  ViewController.m
//  test
//
//  Created by Zhuangyh on 15/12/26.
//  Copyright (c) 2015年 jaga. All rights reserved.
//

#import "ViewController.h"
#import "XHImageViewer.h"
#import "UIImageView+XHURLDownload.h"
#import "WQKImageViewer.h"
#import "JRSwizzle.h"
#import <objc/runtime.h>
#import "UIButton+tagString.h"
@interface ViewController ()//<XHImageViewerDelegate>
@property(nonatomic,strong)NSArray *imageViews;
@end

void swizzleMethod(Class class, SEL originalSelector, SEL swizzledSelector) {
    Method originalMethod = class_getInstanceMethod(class, originalSelector);
    Method swizzledMethod = class_getInstanceMethod(class, swizzledSelector);
    BOOL didAddMethod =
    class_addMethod(class,
                    originalSelector,
                    method_getImplementation(swizzledMethod),
                    method_getTypeEncoding(swizzledMethod));
    if (didAddMethod) {
        class_replaceMethod(class,
                            swizzledSelector,
                            method_getImplementation(originalMethod),
                            method_getTypeEncoding(originalMethod));
    } else {
        method_exchangeImplementations(originalMethod, swizzledMethod);
    }
}

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    self.navigationItem.title = @"你好2";
    self.view.backgroundColor = [UIColor whiteColor];
    
    NSUInteger num = 2400;
    NSLog(@"NSUInteger:%lu :%lu",sizeof(num),num);
    
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        //todo
    });
    
    
//    UIImageView *imageView0 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"Screen"]];
//    [self.view addSubview:imageView0];
//    imageView0.frame = CGRectMake(0, 30, imageView0.image.size.width, imageView0.image.size.height);
    
    
    UIImageView *imageView0 = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 160, 200)];
    [imageView0 setDefaultLoadingView];
    [imageView0 loadWithURL:[NSURL URLWithString:@"http://d.hiphotos.baidu.com/image/h%3D200/sign=22e31b3d324e251ffdf7e3f89787c9c2/72f082025aafa40f282c77daa964034f79f019ca.jpg"] placeholer:[UIImage imageNamed:@"Screen"]];
    [self.view addSubview:imageView0];
    
    UIImageView *imageView1 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"girl_"]];
    [self.view addSubview:imageView1];
    imageView1.frame = CGRectMake(0, 300, imageView1.image.size.width, imageView1.image.size.height);
    
    self.imageViews = @[imageView0,imageView1];

    
    
//    [self.view addSubview:imageViewer];
//    _imageViews is mutiple imageViews(subClass UIImageView or UIImageView)
//    imageView is user touch imageView to selectedImageView
    
   
    
}

- (void)viewWillLayoutSubviews
{
    [super viewWillLayoutSubviews];
    //通过修改约束达到修改布局的效果
    //    self.testViewWidthConstraint.constant = 200;
    
    //    //动画
    //    [UIView animateWithDuration:1 animations:^{
    ////        self.testViewWidthConstraint.constant = 200;
    //        [self.view layoutIfNeeded]; //这句话很重要，只有重新布局才会产生动画效果，否则没有动画效果
    //    }];
    
}


- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
    NSLog(@"touchesBegan");
    ViewController *vc = [[ViewController alloc] init];
    [self.navigationController pushViewController:vc animated:YES];
}

- (IBAction)clickBtn:(id)sender {
    NSLog(@"%s",__FUNCTION__);
    //    WQKImageViewer *imageViewer = [[WQKImageViewer alloc] init];
    //    imageViewer.delegate = self;
    //    [imageViewer showWithImageViews:_imageViews selectedView:_imageViews[1]];
    
}
- (void)swizzle:(id)sender {
    NSLog(@"%s",__FUNCTION__);
//    [self swizzle:sender];
    //    WQKImageViewer *imageViewer = [[WQKImageViewer alloc] init];
    //    imageViewer.delegate = self;
    //    [imageViewer showWithImageViews:_imageViews selectedView:_imageViews[1]];
    
}

+ (void)load {
    NSLog(@"%s",__FUNCTION__);
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        Class class = [self class];
    });
    swizzleMethod([ViewController class],@selector(clickBtn:),@selector(swizzle:));
//     [ViewController jr_swizzleMethod:@selector(clickBtn:) withMethod:@selector(swizzle:) error:nil];
    
}

#pragma mark-dddd

@end
